<template>
  <div class="productDetail">
    <el-form label-width="160px">
      <el-row>
        <el-col :span="10">
          <el-form-item label="商品名称:">{{product.name}}</el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="原价:">{{product.originPrice}}</el-form-item>
        </el-col>

        <el-col :span="10">
          <el-form-item label="现价:">{{product.presentPrice}}</el-form-item>
        </el-col>
      
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="团长佣金占比(%):">{{product.proportion}}</el-form-item>
        </el-col>

        <el-col :span="10">
          <el-form-item label="状态:">{{product.downline == 0 ? '在线': '下线'}}</el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="已售:">{{product.sales}}</el-form-item>
        </el-col>

        <el-col :span="10">
          <el-form-item label="库存:">{{productStock.stock}}</el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="22">
          <el-form-item label="图片:">
            <img v-for="(item,index) in imgUrlArray" :key="index" :src="item" class="cover" >
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item label="描述:">{{product.description}}</el-form-item>
        </el-col>
      
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item>
            <el-button type="primary" @click="goBack()">返 回</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
 
  </div>
</template>

<script>
import api from "@/api/product";

const SUCCESS = 0;
export default {
  data() {
    return {
      id: null,
      product: {},
      productStock: {},
      imgUrlArray: []
    };
  },
  created() {
    this.id = this.$route.query.id;
    if (this.id) {
      this._getDetail();
    } else {
      this.$message({
        type: "warning",
        message: "获取参数失败,请返回列表页重试!"
      });
    }
  },
  methods: {
    _getDetail() {
      api.getDetail(this.id).then(response => {
        if (response.code == SUCCESS) {
          this.product = response.data.product;
          this.productStock = response.data.productStock;

          this.imgUrlArray = this.product.imgUrl.split("#");

        }
      });
    },
    goBack() {
      this.$router.back();
    }
  }
};
</script>

<style lang="less">
.productDetail {
  padding-bottom: 100px;
  .cover {
    width: 150px;
    height: 150px;
    border-radius: 4px;
    border: 1px dashed #d9d9d9;
    display: inline-block;
    margin-right: 14px;
  }
}
</style>